Nimb Game for the HP-15C

Description

The Object of the game is to get your opponent take the last match stick.
You can play an almost endless set of games, because you set the rules
of each game with the A and B function keys.

Example:

3 A (For this game, players can take a maximum of 3 sticks per move)
15 B (Start this game with 15 sticks on the pile)
2 R/S (You pick up 2 sticks, the Calculator picks 1 leaving -12)
3 R/S (You pick 3 sticks, the Calculator picks 1 stick leaving -8)
3 R/S (You pick up 3 sticks, the Calculator picks 1 leaving -4)
3 R/S (You pick up 3 sticks, leaving the Calculator to take the last one)
(Displays 3507.1 I LOSE upside down. You win the Calculator loses)

Program resources

Labels

Name Description
A Sets the maximum number of sticks you can take in each move.
B Sets the number of sticks on the pile to start with.
0 Check validity of player's move, and compute Calculator's move.
1 Game Over (Display Win, or Lose Message)
2 Check to see if Player Won.
4 Display Sticks left on pile (Ready for Player's Move)

Storage Registers

Name Description
0 Total (Pile)
1 Max Grab per move+1
2 I.Lose (upside down Calculator loses You win)
3 Bliss (upside down Calculator wins You lose)

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000    021 31   R/S 042 34   x↔y
001 42.21.11 f LBL A 022 42.21.12 f LBL B 043 44.30. 0   STO 0
002 44 0   STO 0 023 42. 7. 0   f FIX 0 044 45 0   RCL 0
003 1   1 024 44 0   STO 0 045 42 31   f PSE
004 40   ✛ 025 42.21. 4 f LBL 4 046 1   1
005 44 1   STO 1 026 16   CHS 047 30   
006 3   3 027 31   R/S 048 45 1   RCL 1
007 5   5 028 40   ✛ 049 10   ÷
008 0   0 029 43.30. 2   g TEST x<0 050 42 44   f FRAC
009 7   7 030 22 0   GTO 0 051 45 1   RCL 1
010 48   . 031 45 3   RCL 3 052 20   ✕
011 1   1 032 22 1   GTO 1 053 43 20   g x=0
012 44 2   STO 2 033 42.21. 0 f LBL 0 054 1   1
013 5   5 034 43 36   g LSTx 055 44.30. 0   STO 0
014 5   5 035 1   1 056 42.21. 2 f LBL 2
015 1   1 036 43.30. 7   g TEST x>y 057 45 0   RCL 0
016 7   7 037 22 2   GTO 2 058 43.30. 0   g TEST x≠0
017 8   8 038 33   R⬇ 059 22 4   GTO 4
018 44 3   STO 3 039 45 1   RCL 1 060 45 2   RCL 2
019 45 0   RCL 0 040 43 10   g x≤y 061 42. 7. 1   f FIX 1
020 42.21. 1 f LBL 1 041 22 2   GTO 2 062 22 1   GTO 1